local lianjie = fk.CreateSkill {
    name = "mq__lianjie",
    tags = { Skill.Switch },
}

local U = require "packages/utility/utility"

lianjie:addEffect("viewas", {
  anim_type = "support",
  card_filter = function(self, player, to_select, selected)
    return #selected <= player:usedSkillTimes(lianjie.name, Player.HistoryTurn) and player:getSwitchSkillState(lianjie.name) == fk.SwitchYang
  end,
  prompt = function (self, player, selected_cards, selected)
     if player:getSwitchSkillState(lianjie.name) == fk.SwitchYang then
        return "#mq__lianjie:::"..(1 + player:usedSkillTimes(lianjie.name, Player.HistoryTurn))
     end
     return "#no_zhuanhua"
    end,
  handly_pile = true,
  view_as = function (self, player, cards)
    if #cards ~= 1 + player:usedSkillTimes(lianjie.name, Player.HistoryTurn) then return end
    local card = Fk:cloneCard("fire_attack")
    card.skillName = lianjie.name
    card:addSubcards(cards)
    return card
  end,
  before_use = function (self, player, use)
    use.extra_data = use.extra_data or {}
    use.extra_data.mq__lianjie_user = player.id
  end,
})

lianjie:addEffect(fk.DamageCaused, {
  anim_type = "offensive",
  prompt = "令此伤害改为此技能本回合发动次数",
  can_trigger = function(self, event, target, player, data)
    return data.from==player and player:getSwitchSkillState(lianjie.name) == fk.SwitchYin and player:hasSkill(lianjie.name)
  end,
  on_use = function(self, event, target, player, data)
    data:changeDamage(player:usedSkillTimes(lianjie.name, Player.HistoryTurn)-1)
  end,
})

Fk:loadTranslationTable{
  ["mq__lianjie"] = "连捷",
  [":mq__lianjie"] = "<b>转换技</b>，你可以①将X张牌当【火攻】使用②令你造成的伤害改为X（X为本回合此技能发动次数）。",
  ["#mq__lianjie"] = "连捷：将%arg张牌当【火攻】使用",
  ["#no_zhuanhua"] = "此技能状态为阴"
}

return lianjie